package run.siyuan.elasticsearch.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.client.ClientConfiguration;
import org.springframework.data.elasticsearch.client.RestClients;

/**
 * @className: ElasticSearchClientConfig
 * @Description: TODO
 * @author: siyuan
 * @date: 2022/5/30 3:13 PM
 */
@Configuration
public class ElasticSearchClientConfig {

    @Value("${spring.elasticsearch.rest.uris}")
    private String urls;


    @Bean
    public RestHighLevelClient restHighLevelClient() {
//        RestHighLevelClient restHighLevelClient = new RestHighLevelClient(
//                RestClient.builder(
//                        new HttpHost("8.214.61.239", 9210, "http")
//                )
//        );
//        return restHighLevelClient;
        ClientConfiguration clientConfiguration = ClientConfiguration.builder()
                .connectedTo("8.214.61.239:9210")
                .build();

        RestHighLevelClient client = RestClients.create(clientConfiguration).rest();
        return client;


    }
}
